package demo.oo.trains;

import java.util.ArrayList;
import java.util.List;

/**
 * CompositeRoute is consisted with {@link Edge}s
 * 
 * @author lifany
 * 
 */
public class Path extends Route {
	private List<Route> routes;

	public Path(String startPoint, String endPoint) {
		this.startPoint = startPoint;
		this.endPoint = endPoint;
	}

	public Path(String startPoint, String endPoint, List<Route> routes) {
		this.startPoint = startPoint;
		this.endPoint = endPoint;
		this.routes = routes;
	}

	public boolean isComplete() {
		if (routes == null || routes.isEmpty())
			return false;
		return routes.get(routes.size() - 1).getEndPoint().equals(endPoint);
	}

	@Override
	public int getLength() {
		int length = 0;
		for (Route route : routes) {
			length += route.getLength();
		}
		return length;
	}

	public List<Route> getRoutes() {
		if (routes == null)
			routes = new ArrayList<Route>();
		return routes;
	}

	@Override
	public String toString() {
		StringBuilder message = new StringBuilder("The path between " + startPoint + " and " + endPoint + " is: ");

		for (int i = 0; i < routes.size(); i++) {
			message.append(routes.get(i).getStartPoint());
			message.append(routes.get(i).getEndPoint());
			if (i != routes.size() - 1)
				message.append("->");
		}

		return message.toString();
	}
}
